package com.zhb.lkd.controller;


import com.zhb.lkd.base.PageResponse;
import com.zhb.lkd.base.ResponseResult;
import com.zhb.lkd.exception.BusinessException;
import com.zhb.lkd.pojos.entity.Node;
import com.zhb.lkd.pojos.entity.Partner;
import com.zhb.lkd.pojos.vo.PartnerVo;
import com.zhb.lkd.pojos.vo.VmListNodeVo;
import com.zhb.lkd.service.INodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 点位表 前端控制器
 * </p>
 *
 * @author haibin
 * @since 2024-08-18
 */
@RestController
@RequestMapping("/api/vm-service/node")
@Slf4j
@Api(tags = "点位管理相关接口")
public class NodeController {
    @Resource
    private INodeService nodeService;

    @GetMapping("/search")
    @ApiOperation("查看区域详情")
    public ResponseResult search(
            @RequestParam(defaultValue = "1") Integer pageIndex,
            @RequestParam(defaultValue = "10") Integer pageSize,
            String regionId, String name) {
        log.info("查看区域详情{}", regionId);
        PageResponse pageResponse = nodeService.search(pageIndex, pageSize, regionId, name);
        return ResponseResult.ok(pageResponse);
    }


    @PostMapping("")
    @ApiOperation("新增点位")
    public ResponseResult create(@RequestBody Node node) {
        log.info("新增点位{}", node);
        nodeService.create(node);
        return ResponseResult.ok();
    }

    @GetMapping("/vmList/{nodeId}")
    @ApiOperation("获取点位详情根据点位id查询设备列表")
    public ResponseResult findById(@PathVariable String nodeId) {
        log.info("获取点位详情{}", nodeId);
        List<VmListNodeVo> vmListNodeVos = nodeService.findById(nodeId);
        return ResponseResult.ok(vmListNodeVos);
    }

    @PutMapping()
    @ApiOperation("修改点位")
    public ResponseResult updateById(@RequestBody Node node) {
        log.info("修改点位{}", node);
        if (node.getId()==0||node.getId()==null){
            throw new BusinessException(500,"合作商id不能为空");
        }
        boolean b = nodeService.updateById(node);
        return ResponseResult.ok();
    }


    @DeleteMapping("/{nodeId}")
    @ApiOperation("删除合作商")
    public ResponseResult deleteById(@PathVariable String nodeId) {
        log.info("删除合作商{}", nodeId);
        nodeService.deleteById(nodeId);
        return ResponseResult.ok();
    }
}
